package logic

import (
	"context"
	"gorm.io/gorm"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpdateLogic) UserUpdate(in *productrpc.UserUpdateRequest) (*productrpc.UserUpdateResponse, error) {
	// todo: add your logic here and delete this line

	product := mysql.Product{
		Model: gorm.Model{ID: uint(in.Id)},
		Img:   in.Img,
		Name:  in.Name,
		Price: float64(in.Price),
		Num:   int(in.Num),
	}
	mysql.DB.Debug().Updates(&product)

	return &productrpc.UserUpdateResponse{Id: int64(product.ID)}, nil
}
